package com.xiaoxi.exam.dao;

import com.xiaoxi.exam.model.PreOrder;
import com.xiaoxi.exam.model.PreOrderExample;
import java.util.List;
import org.apache.ibatis.annotations.Delete;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Options;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.ResultMap;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;

public interface PreOrderMapper {
    /**
     * This method was generated by MyBatis Generator.
     * This method corresponds to the database table s_business.t_pre_order
     *
     * @mbg.generated Sun Dec 09 21:21:59 CST 2018
     */
    long countByExample(PreOrderExample example);

    /**
     * This method was generated by MyBatis Generator.
     * This method corresponds to the database table s_business.t_pre_order
     *
     * @mbg.generated Sun Dec 09 21:21:59 CST 2018
     */
    int deleteByExample(PreOrderExample example);

    /**
     * This method was generated by MyBatis Generator.
     * This method corresponds to the database table s_business.t_pre_order
     *
     * @mbg.generated Sun Dec 09 21:21:59 CST 2018
     */
    @Update({
        "update s_business.t_pre_order",
        "set deleted_at = now()",
        "where id = #{id,jdbcType=BIGINT}"
    })
    int deleteByPrimaryKey(Long id);

    /**
     * This method was generated by MyBatis Generator.
     * This method corresponds to the database table s_business.t_pre_order
     *
     * @mbg.generated Sun Dec 09 21:21:59 CST 2018
     */
    @Select({
        "insert into s_business.t_pre_order (user_id, phone, ",
        "code, status, created_at, ",
        "updated_at, deleted_at, ",
        "total_amount, trade_no, ",
        "order_time, pay_time)",
        "values (#{userId,jdbcType=BIGINT}, #{phone,jdbcType=VARCHAR}, ",
        "#{code,jdbcType=VARCHAR}, #{status,jdbcType=SMALLINT}, #{createdAt,jdbcType=TIMESTAMP}, ",
        "#{updatedAt,jdbcType=TIMESTAMP}, #{deletedAt,jdbcType=TIMESTAMP}, ",
        "#{totalAmount,jdbcType=INTEGER}, #{tradeNo,jdbcType=VARCHAR}, ",
        "#{orderTime,jdbcType=TIMESTAMP}, #{payTime,jdbcType=TIMESTAMP})", 
        " returning id"
    })
    @Options(useGeneratedKeys=true,keyProperty="id")
    long insertReturningId(PreOrder record);

    /**
     * This method was generated by MyBatis Generator.
     * This method corresponds to the database table s_business.t_pre_order
     *
     * @mbg.generated Sun Dec 09 21:21:59 CST 2018
     */
    @Insert({
        "insert into s_business.t_pre_order (user_id, phone, ",
        "code, status, created_at, ",
        "updated_at, deleted_at, ",
        "total_amount, trade_no, ",
        "order_time, pay_time)",
        "values (#{userId,jdbcType=BIGINT}, #{phone,jdbcType=VARCHAR}, ",
        "#{code,jdbcType=VARCHAR}, #{status,jdbcType=SMALLINT}, #{createdAt,jdbcType=TIMESTAMP}, ",
        "#{updatedAt,jdbcType=TIMESTAMP}, #{deletedAt,jdbcType=TIMESTAMP}, ",
        "#{totalAmount,jdbcType=INTEGER}, #{tradeNo,jdbcType=VARCHAR}, ",
        "#{orderTime,jdbcType=TIMESTAMP}, #{payTime,jdbcType=TIMESTAMP})"
    })
    @Options(useGeneratedKeys=true,keyProperty="id")
    int insert(PreOrder record);

    /**
     * This method was generated by MyBatis Generator.
     * This method corresponds to the database table s_business.t_pre_order
     *
     * @mbg.generated Sun Dec 09 21:21:59 CST 2018
     */
    long insertSelectiveReturningId(PreOrder record);

    /**
     * This method was generated by MyBatis Generator.
     * This method corresponds to the database table s_business.t_pre_order
     *
     * @mbg.generated Sun Dec 09 21:21:59 CST 2018
     */
    int insertSelective(PreOrder record);

    /**
     * This method was generated by MyBatis Generator.
     * This method corresponds to the database table s_business.t_pre_order
     *
     * @mbg.generated Sun Dec 09 21:21:59 CST 2018
     */
    List<PreOrder> selectByExample(PreOrderExample example);

    /**
     * This method was generated by MyBatis Generator.
     * This method corresponds to the database table s_business.t_pre_order
     *
     * @mbg.generated Sun Dec 09 21:21:59 CST 2018
     */
    @Select({
        "select",
        "id, user_id, phone, code, status, created_at, updated_at, deleted_at, total_amount, ",
        "trade_no, order_time, pay_time",
        "from s_business.t_pre_order",
        "where id = #{id,jdbcType=BIGINT}"
    })
    @ResultMap("com.xiaoxi.exam.dao.PreOrderMapper.BaseResultMap")
    PreOrder selectByPrimaryKey(Long id);

    /**
     * This method was generated by MyBatis Generator.
     * This method corresponds to the database table s_business.t_pre_order
     *
     * @mbg.generated Sun Dec 09 21:21:59 CST 2018
     */
    int updateByExampleSelective(@Param("record") PreOrder record, @Param("example") PreOrderExample example);

    /**
     * This method was generated by MyBatis Generator.
     * This method corresponds to the database table s_business.t_pre_order
     *
     * @mbg.generated Sun Dec 09 21:21:59 CST 2018
     */
    int updateByExample(@Param("record") PreOrder record, @Param("example") PreOrderExample example);

    /**
     * This method was generated by MyBatis Generator.
     * This method corresponds to the database table s_business.t_pre_order
     *
     * @mbg.generated Sun Dec 09 21:21:59 CST 2018
     */
    int updateByPrimaryKeySelective(PreOrder record);

    /**
     * This method was generated by MyBatis Generator.
     * This method corresponds to the database table s_business.t_pre_order
     *
     * @mbg.generated Sun Dec 09 21:21:59 CST 2018
     */
    @Update({
        "update s_business.t_pre_order",
        "set user_id = #{userId,jdbcType=BIGINT},",
          "phone = #{phone,jdbcType=VARCHAR},",
          "code = #{code,jdbcType=VARCHAR},",
          "status = #{status,jdbcType=SMALLINT},",
          "created_at = #{createdAt,jdbcType=TIMESTAMP},",
          "updated_at = #{updatedAt,jdbcType=TIMESTAMP},",
          "deleted_at = #{deletedAt,jdbcType=TIMESTAMP},",
          "total_amount = #{totalAmount,jdbcType=INTEGER},",
          "trade_no = #{tradeNo,jdbcType=VARCHAR},",
          "order_time = #{orderTime,jdbcType=TIMESTAMP},",
          "pay_time = #{payTime,jdbcType=TIMESTAMP}",
        "where id = #{id,jdbcType=BIGINT}"
    })
    int updateByPrimaryKey(PreOrder record);
}